package com.itheima.reggie.mapper;

import com.itheima.reggie.dto.SetmealDto;
import com.itheima.reggie.entity.Setmeal;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface SetmealMapper {
    @Select("select count(*) from setmeal where category_id=#{id};")//根据id查询只能查出一行，因此要用聚合函数统计数量！
    long findById(Long id);
    @Insert("insert into setmeal values(null,#{categoryId},#{name},#{price},#{status},#{code},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser},0);")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    void saveWithDish(SetmealDto setmealDto);

    List<Setmeal> page(int page, int pageSize, String name);
//    @Delete("delete from setmeal where id=#{id};")
    void deleteByIdsWithDish(@Param("ids") List<Long> ids);
    @Select("select *from setmeal where id=#{id};")
    Setmeal findByIdAndDish(Long id);

    void updateWithDish(SetmealDto setmealDto);

    Long queryWithSetmealDishStatus(@Param("ids") List<Long> ids);

    void updateStatusZero(@Param("ids") List<Long> ids, @Param("empId") Long empId, @Param("updateTime") LocalDateTime updateTime);

    void updateStatusOne(@Param("ids") List<Long> ids,@Param("empId") Long empId, @Param("updateTime") LocalDateTime updateTime);
//    @Select("select *from setmeal where category_id=#{id} and status=#{status};")
    List<Setmeal> list(@Param("categoryId") Long categoryId, @Param("status") Integer status);
}
